home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / forms / dbgrid1 / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-10-16  |  24.4 KB  |  646 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   6090
  5.    ClientLeft      =   3390
  6.    ClientTop       =   1965
  7.    ClientWidth     =   5580
  8.    Height          =   6495
  9.    Left            =   3330
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   6090
  12.    ScaleWidth      =   5580
  13.    Top             =   1620
  14.    Width           =   5700
  15.    Begin VB.CommandButton cmdUnselectRows 
  16.       Caption         =   "Unselect Rows"
  17.       Height          =   372
  18.       Left            =   3600
  19.       TabIndex        =   11
  20.       Top             =   5400
  21.       Width           =   1452
  22.    End
  23.    Begin VB.TextBox Text2 
  24.       Height          =   390
  25.       Left            =   1635
  26.       TabIndex        =   3
  27.       Text            =   "0"
  28.       Top             =   4350
  29.       Width           =   480
  30.    End
  31.    Begin VB.TextBox Text1 
  32.       Height          =   390
  33.       Left            =   720
  34.       TabIndex        =   2
  35.       Text            =   "0"
  36.       Top             =   4350
  37.       Width           =   480
  38.    End
  39.    Begin VB.CommandButton cmdSelectCols 
  40.       Caption         =   "Sel &Cols"
  41.       Height          =   375
  42.       Left            =   2400
  43.       TabIndex        =   1
  44.       Top             =   4320
  45.       Width           =   1080
  46.    End
  47.    Begin VB.CommandButton cmdGetBookmark 
  48.       Caption         =   "Save Cur Row"
  49.       Height          =   372
  50.       Left            =   240
  51.       TabIndex        =   9
  52.       Top             =   4920
  53.       Width           =   1452
  54.    End
  55.    Begin VB.CommandButton cmdSetBookmark 
  56.       Caption         =   "GoTo Saved Row"
  57.       Height          =   372
  58.       Left            =   240
  59.       TabIndex        =   8
  60.       Top             =   5400
  61.       Width           =   1452
  62.    End
  63.    Begin VB.CommandButton cmdPhonyDCFirst 
  64.       Caption         =   "|<"
  65.       Height          =   252
  66.       Left            =   240
  67.       TabIndex        =   7
  68.       Top             =   240
  69.       Width           =   252
  70.    End
  71.    Begin VB.CommandButton cmdPhonyDCPrevious 
  72.       Caption         =   "<"
  73.       Height          =   252
  74.       Left            =   480
  75.       TabIndex        =   13
  76.       Top             =   240
  77.       Width           =   252
  78.    End
  79.    Begin VB.CommandButton cmdPhonyDCNext 
  80.       Caption         =   ">"
  81.       Height          =   252
  82.       Left            =   2280
  83.       TabIndex        =   14
  84.       Top             =   240
  85.       Width           =   252
  86.    End
  87.    Begin VB.CommandButton cmdPhonyDCLast 
  88.       Caption         =   ">|"
  89.       Height          =   252
  90.       Left            =   2520
  91.       TabIndex        =   15
  92.       Top             =   240
  93.       Width           =   252
  94.    End
  95.    Begin VB.CommandButton cmdDeleteCurrent 
  96.       Caption         =   "Delete Current"
  97.       Height          =   372
  98.       Left            =   1920
  99.       TabIndex        =   16
  100.       Top             =   4920
  101.       Width           =   1452
  102.    End
  103.    Begin VB.CommandButton cmdSelectRows 
  104.       Caption         =   "Select Rows"
  105.       Height          =   372
  106.       Left            =   3600
  107.       TabIndex        =   17
  108.       Top             =   4920
  109.       Width           =   1452
  110.    End
  111.    Begin VB.CommandButton cmdWildCard 
  112.       Caption         =   "Wild Card"
  113.       Height          =   372
  114.       Left            =   1920
  115.       TabIndex        =   18
  116.       Top             =   5400
  117.       Width           =   1452
  118.    End
  119.    Begin VB.CommandButton cmdAddNew 
  120.       Caption         =   "Add New"
  121.       Height          =   375
  122.       Left            =   3840
  123.       TabIndex        =   0
  124.       Top             =   4320
  125.       Width           =   1215
  126.    End
  127.    Begin VB.Shape Shape1 
  128.       Height          =   855
  129.       Left            =   120
  130.       Top             =   3960
  131.       Width           =   3495
  132.    End
  133.    Begin VB.Label Label3 
  134.       Caption         =   "to:  "
  135.       Height          =   285
  136.       Left            =   1335
  137.       TabIndex        =   6
  138.       Top             =   4320
  139.       Width           =   225
  140.    End
  141.    Begin VB.Label Label2 
  142.       Caption         =   "from:  "
  143.       Height          =   240
  144.       Left            =   300
  145.       TabIndex        =   5
  146.       Top             =   4350
  147.       Width           =   330
  148.    End
  149.    Begin VB.Label Label4 
  150.       Caption         =   "Select Columns in code"
  151.       BeginProperty Font 
  152.          name            =   "MS Sans Serif"
  153.          charset         =   0
  154.          weight          =   400
  155.          size            =   9.75
  156.          underline       =   -1  'True
  157.          italic          =   0   'False
  158.          strikethrough   =   0   'False
  159.       EndProperty
  160.       Height          =   285
  161.       Left            =   360
  162.       TabIndex        =   4
  163.       Top             =   3960
  164.       Width           =   2175
  165.    End
  166.    Begin MSDBGrid.DBGrid DBGrid1 
  167.       Height          =   3015
  168.       Left            =   120
  169.       OleObjectBlob   =   "Form1.frx":0000
  170.       TabIndex        =   12
  171.       Top             =   720
  172.       Width           =   5295
  173.    End
  174.    Begin VB.Label Label1 
  175.       Alignment       =   2  'Center
  176.       BackColor       =   &H00FFFFFF&
  177.       BorderStyle     =   1  'Fixed Single
  178.       Caption         =   "Phony Data Control"
  179.       Height          =   255
  180.       Left            =   720
  181.       TabIndex        =   10
  182.       Top             =   240
  183.       Width           =   1575
  184.    End
  185. Attribute VB_Name = "Form1"
  186. Attribute VB_Creatable = False
  187. Attribute VB_Exposed = False
  188. '==================================================================='
  189. 'The following text contains a sample for manipulating data in an
  190. 'Unbound grid using an array for data storage.
  191. '==================================================================='
  192. 'Data storage variables.  Dimensions and a place to put the data
  193. Dim MaxRow As Integer       ' number of rows in array
  194. Dim MaxCol As Integer       ' number of columns in array
  195. Dim dataval() As Variant    ' a variable array to store the data.
  196. 'Other global variables
  197. Dim ToMe As Variant         ' a bookmark for Get/Set Bookmark tests
  198. Private Sub Form_Activate()
  199. loadedflag = 1
  200. End Sub
  201. Private Sub Form_Load()
  202.     'Set up, allocate and fill the data array.  For this example
  203.     'the data is manufactured for simplicity.  The user is queried
  204.     'for the initial number of rows.
  205.     'The number of columns is taken as the number of columns set
  206.     'up in the property pages.  Get to the property pages by
  207.     'right-clicking on the grid at design time.  Select "Edit" to
  208.     'get to the layout editor.  Columns can be inserted,appended and
  209.     'deleted from the layout editor.  You must set focus to another control on
  210.     'to leave the layout editor.  You can tell the grid is in the layout
  211.     'editor by the cursor that is visible in the grid.  Column properties
  212.     'can be changed by selecting "Properties" from the pop-up menu.
  213.     'Get the dimensions of the data storage array, dataval
  214.     MaxRow = 10 'Val(InputBox("Enter number of starting rows"))
  215.     MaxCol = DBGrid1.Columns.Count
  216.     'If zero initial rows are requested, additional set is
  217.     'unnecessary
  218.     If MaxRow <= 0 Then Exit Sub
  219.     'The data array, dataval, is allocated with the
  220.     'columns as the first index.  Columns are first since
  221.     'the column count is fixed, and the number of rows may
  222.     'change.  This allows us to "ReDim Preserve" for added
  223.     'and deleted rows.
  224.     ReDim dataval(0 To MaxCol - 1, 0 To MaxRow - 1)
  225.     Dim row, col As Integer
  226.     For row = 0 To MaxRow - 1
  227.        For col = 0 To MaxCol - 1
  228.           dataval(col, row) = "(R" & row & ", C" & col & ")"
  229.        Next col
  230.     Next row
  231. End Sub
  232. 'These routines demonstrate Unbound grid manipulations
  233. 'through VBA code.
  234. Private Sub cmdAddNew_Click()
  235.     'This button event positions the user to
  236.     'the Grid AddNew row.
  237.     If DBGrid1.AllowAddNew Then
  238.         If MaxRow > 0 Then
  239.             'position to the last row.  Moving twice causes
  240.             'a pending AddNew to update, and then become the
  241.             'last row for the second MoveLast
  242.             cmdPhonyDCLast_Click   'defined below
  243.            
  244.             cmdPhonyDCLast_Click
  245.         End If
  246.         'position to the next grid row
  247.         DBGrid1.col = 0
  248.         DBGrid1.row = DBGrid1.row + 1
  249.     End If
  250.     DBGrid1.SetFocus
  251. End Sub
  252. Private Sub cmdGetBookmark_Click()
  253.     'This button event obtains the bookmark for the
  254.     'current row and stores it for later use by the
  255.     '"Set Bookmark" button.
  256.     ToMe = DBGrid1.bookMark
  257. End Sub
  258. Private Sub cmdSetBookmark_Click()
  259.     'This button event moves to the row which was current
  260.     'the last time the "Get Bookmark" button was pressed.
  261.     DBGrid1.bookMark = ToMe
  262. End Sub
  263. Private Sub cmdDeleteCurrent_Click()
  264.     'This button event deletes the current row
  265.     On Error GoTo BadBkmk
  266.     'the current row must be selected to delete it
  267.     DBGrid1.SelBookmarks.Add DBGrid1.bookMark
  268.     DBGrid1.SetFocus
  269.     SendKeys "{DEL}"
  270.     Exit Sub
  271. BadBkmk:
  272.     MsgBox "There are no rows to delete."
  273. End Sub
  274. Private Sub cmdWildCard_Click()
  275.     'This button event allows the user to position
  276.     'to any row within the grid by generating a bookmark
  277.     'and positioning the grid.  This can only be done
  278.     'because our VBA code as knowledge of the internal
  279.     'meaning of the bookmark.
  280.     '
  281.     'Note that the VBA makeBookmark() function is used
  282.     'to manufacture the bookmark.
  283.     Dim result As Integer
  284.     result = Val(InputBox("Enter row number"))
  285.     DBGrid1.bookMark = makeBookmark(result)
  286. End Sub
  287. Private Sub cmdSelectCols_Click()
  288. 'select columns specified in textboxes
  289. 'workaround
  290.     Dim hi As Integer
  291.     Dim lo As Integer
  292.     lo = Val(Text1.Text)
  293.     hi = Val(Text2.Text)
  294.         
  295.     'workaround::needs to be reset
  296.     DBGrid1.SelStartCol = 0
  297.     'workaround::if columns with higher index numbers are previously_
  298.     'selected, the selection will not take place
  299.     If DBGrid1.SelEndCol > hi Then
  300.         DBGrid1.SelEndCol = hi
  301.     End If
  302.     'workaround::notice Start is assigned the higher number_
  303.     'and it is assigned twice
  304.     DBGrid1.SelStartCol = hi
  305.     DBGrid1.SelStartCol = hi
  306.     DBGrid1.SelEndCol = lo
  307. End Sub
  308. Private Sub cmdSelectRows_Click()
  309.     'This button event causes every other visible row to be
  310.     'selected, starting with the first row.
  311.     Dim rowbmk As Variant
  312.     Dim rowcnt As Long
  313.     Dim row As Long
  314.     'position to the first row on the grid
  315.     DBGrid1.bookMark = DBGrid1.FirstRow
  316.     'get count of visible rows
  317.     rowcnt = DBGrid1.VisibleRows
  318.         
  319.     'select every other row.  It is possible that we may request
  320.     'an invalid bookmark (passed EOF, i.e. the AddNew line), so we
  321.     'include some error processing to handle this.
  322.     On Error GoTo LoopExit
  323.     For row = 0 To rowcnt Step 2
  324.         rowbmk = DBGrid1.GetBookmark(row)
  325.         DBGrid1.SelBookmarks.Add rowbmk
  326.     Next row
  327. LoopExit:
  328.     Exit Sub
  329. End Sub
  330. Private Sub cmdUnselectRows_Click()
  331.     'This button event deselects all Selected Rows
  332.     While DBGrid1.SelBookmarks.Count
  333.         DBGrid1.SelBookmarks.Remove 0
  334.     Wend
  335. End Sub
  336. 'Utility Functions
  337. Private Function isAddNew() As Boolean
  338.     'This function determines if an AddNew is being processed
  339.     'For an AddNew to be in operation, the grid must
  340.     'be in a modified state.
  341.     'If DBGrid1.DataChanged Then     'True DBGrid only
  342.         'if there is currently no data, it must be AddNew
  343.         If MaxRow = 0 Then
  344.             isAddNew = True
  345.             Exit Function
  346.         End If
  347.         
  348.         'the modified row is an AddNew and not an update
  349.         'if the current row bookmark and current row are
  350.         'not indicating the same row.  This happens because
  351.         'an AddNew does not change the current row (in the
  352.         'database sense), but a different physical row of
  353.         'the grid is being editted.
  354.         
  355.         Dim curindex, topindex As Integer
  356.         curindex = GetArrayIndex(DBGrid1.bookMark, False)
  357.         topindex = GetArrayIndex(DBGrid1.FirstRow, False)
  358.         If (curindex - topindex) <> DBGrid1.row Then
  359.             isAddNew = True
  360.             Exit Function
  361.         End If
  362.     'End If
  363.     isAddNew = False
  364. End Function
  365. 'The following functions manage the data array
  366. 'addressing, both through indices and bookMarks
  367. 'and provide appropriate conversion from array
  368. 'indices to bookmarks and back again.
  369. Private Function isInvalidIndex(ByVal rindex As Integer) As Boolean
  370.     If rindex < 0 Or rindex >= MaxRow Then
  371.         isInvalidIndex = True
  372.     Else
  373.         isInvalidIndex = False
  374.     End If
  375. End Function
  376. Private Function makeBookmark(rindex As Integer) As Variant
  377.     'It is important that bookmarks be generated in a
  378.     'consistant manner throughout the code.  The importance
  379.     'of this cannot be overstressed.
  380.     '
  381.     'The grid handles bookmarks as "blackbox" objects - i.e.
  382.     'as objects for which the internal data has no meaning.
  383.     'This means that "01" and " 1" and "1" are all considered
  384.     'different, even though the interpretted numeric value is
  385.     'the same.
  386.     '
  387.     'Therefore, care must be taken to avoid using different
  388.     'means for generating bookmarks which refer to the same
  389.     'row.  For example,
  390.     '
  391.     '              Format$(1) produces the string "1"
  392.     '   while,     Str$(1) will generate " 1".
  393.     '
  394.     'These are clearly different in the blackbox sense and
  395.     'so will be treated differently by the grid, even though
  396.     'both strings are derived from the same numeric value.
  397.     '
  398.     'To avoid such difficulties, we use a single VBA function
  399.     'to manage the creation of bookmarks, thus insuring
  400.     'consistency.  If the method of generation must change
  401.     'as the code evolves, we can simply change this function
  402.     'and still guarrantee bookmark consistency.
  403.     makeBookmark = Str(rindex)
  404. End Function
  405. Private Function GetArrayIndex(bookMark As Variant, _
  406.               ReadPriorRows As Boolean) As Integer
  407.     If IsNull(bookMark) Then
  408.         
  409.         'A Null bookmark indicates BOF or EOF, depending upon
  410.         'direction.  If the grid is requesting ReadPriorRows,
  411.         'then Null refers to EOF.  If ReadPriorRows is not
  412.         'True valued, then Null represents BOF
  413.         If ReadPriorRows Then
  414.             GetArrayIndex = MaxRow  'EOF of the array
  415.         Else
  416.             GetArrayIndex = -1      'BOF of the array
  417.         End If
  418.         Exit Function
  419.     Else
  420.         
  421.         'Determine the array index from the bookmark.  This
  422.         'function must invert the bookmark construction process
  423.         'of the makeBookmark() function.  Again, this is handled
  424.         'in a single function to assure consistency and allow
  425.         'easy methodology changes as our code evolves.
  426.         Dim bk As Integer
  427.         bk = Val(bookMark)
  428.         If bk >= 0 And bk < MaxRow Then
  429.             GetArrayIndex = bk
  430.             Exit Function
  431.         End If
  432.     End If
  433.     'We should never get here.  Return an index that is "way bad"
  434.     'such that minor increments of the value do not produce a
  435.     'valid index.  This simplifies code elsewhere.
  436.     GetArrayIndex = -2000
  437. End Function
  438. 'Set up some buttons to emulate a Data Control
  439. 'Special bookmarks can be generated from internal
  440. 'knowledge of the data storage method (an array index)
  441. 'When possible, it is best obtain bookmarks from the
  442. 'grid rather than manufacturing them.  This insures
  443. 'consistency of bookmarks better than any other method.
  444. 'In some cases, special bookmarks may require local
  445. 'generation - e.g. First and Last.  In these cases,
  446. 'note that our VBA makeBookmark() function is used to
  447. 'insure bookmark consistency
  448. Private Sub cmdPhonyDCFirst_Click()
  449.     DBGrid1.bookMark = makeBookmark(0)
  450. End Sub
  451. Private Sub cmdPhonyDCLast_Click()
  452.     DBGrid1.bookMark = makeBookmark(MaxRow - 1)
  453. End Sub
  454. Private Sub cmdPhonyDCNext_Click()
  455.     Dim rindex As Integer
  456.     'make sure the next row is valid
  457.     rindex = GetArrayIndex(DBGrid1.bookMark, False) + 1
  458.     If isInvalidIndex(rindex) Then
  459.         DBGrid1.SetFocus
  460.     Else
  461.         DBGrid1.bookMark = DBGrid1.GetBookmark(1)
  462.     End If
  463. End Sub
  464. Private Sub cmdPhonyDCPrevious_Click()
  465.     Dim rindex As Integer
  466.     'make sure the previous row is valid
  467.     rindex = GetArrayIndex(DBGrid1.bookMark, False) - 1
  468.     If isInvalidIndex(rindex) Then
  469.         DBGrid1.SetFocus
  470.     Else
  471.         DBGrid1.bookMark = DBGrid1.GetBookmark(-1)
  472.     End If
  473. End Sub
  474. 'The Unbound Events
  475. 'The RowBuffer object, passed to the grid events is an OLE
  476. 'object.  Though efficient, resolution of references to
  477. 'RowBuffer members requires some overhead.  Thus, we use
  478. 'local variable whenever possible to store information
  479. 'which does not change for the duration of the event,
  480. 'especially for situations involving loops.
  481. 'Thus, RowBuf.RowCount and RowBuf.ColumnCount values are
  482. 'cached in local variables for the duration of the event.
  483. Private Sub DBGrid1_UnboundAddData(ByVal RowBuf As RowBuffer, _
  484.                 NewRowBookmark As Variant)
  485.     'reallocate the array to include an extra row
  486.     ReDim Preserve dataval(0 To MaxCol - 1, 0 To MaxRow)
  487.     'Get the column limit of the columns to be processed.
  488.     Dim collimit As Integer     'limit of RowBuffer columns
  489.     collimit = RowBuf.ColumnCount - 1
  490.     'check each column for an updated value.  For Add and
  491.     'Write operations, the RowBuffer object is a "sparse"
  492.     'storage object, containing Null values for row/column
  493.     'combinations which have not been modified and therefore
  494.     'should not be used as data.
  495.     Dim col As Integer          'column indicator for RowBuffer
  496.     For col = 0 To collimit
  497.         If Not IsNull(RowBuf.Value(0, col)) Then
  498.             dataval(col, MaxRow) = RowBuf.Value(0, col)
  499.         Else
  500.             'Unbound mode does not have a database to fill in
  501.             'the default values.  We can use what is stored in
  502.             'the column default, or we stick in anything else we
  503.             'wanted, including something that depends on the other
  504.             'column or row data.  But in this case, we'll just
  505.             'use the column default.
  506.             dataval(col, MaxRow) = DBGrid1.Columns(col).DefaultValue
  507.         End If
  508.     Next col
  509.     'set the bookmark for the added row
  510.     NewRowBookmark = makeBookmark(MaxRow)
  511.     'increment the row count
  512.     MaxRow = MaxRow + 1
  513. End Sub
  514. Private Sub DBGrid1_UnboundDeleteRow(bookMark As Variant)
  515.     'if there are no rows to delete, set the bookmark to Null
  516.     'to indicate an error and return immediately.
  517.     If MaxRow = 0 Then
  518.         bookMark = Null
  519.         Exit Sub
  520.     End If
  521.     'the grid refreshes all of its bookmarks after the deletion
  522.     'occurs.  Therefore, we can just remove the element from
  523.     'the data array.  However, if VBA code is storing bookmarks
  524.     'for later use, another approach should be taken such that
  525.     'deleted "rows" become invalid
  526.     'get the array index of the row after the row to be deleted
  527.     Dim rindex As Integer       'dataval array index for the "row"
  528.     rindex = GetArrayIndex(bookMark, False) + 1
  529.     'move the data after the delete row up one row, thus
  530.     'eliminating the deleted row from the data array
  531.     Dim col As Integer          'column of data array
  532.     While Not isInvalidIndex(rindex)
  533.         For col = 0 To MaxCol - 1
  534.             dataval(col, rindex - 1) = dataval(col, rindex)
  535.         Next col
  536.         rindex = rindex + 1
  537.     Wend
  538.     'decrement the row count, and reallocate the array preserving
  539.     'the existing data.  If the last row is being deleted,
  540.     'it is not necessary to change the allocation.
  541.     MaxRow = MaxRow - 1
  542.     If MaxRow <> 0 Then
  543.         ReDim Preserve dataval(0 To MaxCol - 1, 0 To MaxRow - 1)
  544.     End If
  545. End Sub
  546. Private Sub DBGrid1_UnboundReadData(ByVal RowBuf As RowBuffer, StartLocation As Variant, ByVal ReadPriorRows As Boolean)
  547.     'if there is no data, then flag no rows available and return
  548.     If MaxRow = 0 Then
  549.         RowBuf.RowCount = 0
  550.         Exit Sub
  551.     End If
  552.     Dim rowsFetched As Integer      'track count of RowBuf rows set
  553.     rowsFetched = 0     'track the number of rows we fetch
  554.     'Unfortunately, the VB DBGrid help is misleading, even though
  555.     'the example is clear.
  556.     '  ReadPriorRows = True means the RowBuffer wants the rows
  557.     '                  BEFORE the StartLocation.
  558.     'Therefore, we must move backward in our array when filling
  559.     'the buffer.  We always move forward in the RowBuffer itself.
  560.     Dim incr As Integer
  561.     If ReadPriorRows Then
  562.         incr = -1       'move backward in array
  563.     Else
  564.         incr = 1        'move forward in array
  565.     End If
  566.     'Find the array index of the starting row.
  567.     Dim rindex As Integer           'the array (row) index for data
  568.     rindex = GetArrayIndex(StartLocation, ReadPriorRows)
  569.     'The first row to receive a value, is the first increment passed
  570.     'the starting row
  571.     rindex = rindex + incr
  572.     'use rowlimit and collimit as the number of rows and columns
  573.     'requested by the row buffer
  574.     Dim rowlimit, collimit As Integer   'row and column limits for loop
  575.     rowlimit = RowBuf.RowCount - 1
  576.     collimit = RowBuf.ColumnCount - 1
  577.     Dim row, col As Integer         'row and column counters for RowBuf
  578.     For row = 0 To rowlimit
  579.         
  580.         'check to see if we are out of "rows" in the array
  581.         If isInvalidIndex(rindex) Then Exit For
  582.         
  583.         'fill in the RowBuffer columns
  584.         For col = 0 To collimit
  585.             'do not allow empty variants to be put into rowbuffer
  586.             If VarType(dataval(col, rindex)) = 0 Then
  587.                 dataval(col, rindex) = Null
  588.             End If
  589.                         
  590.             RowBuf.Value(row, col) = dataval(col, rindex)
  591.         Next col
  592.         'derive a bookmark that makes it easy to find the array rindex
  593.         'makeBookmark creates the bookmark, GetArrayIndex interprets it.
  594.         RowBuf.bookMark(row) = makeBookmark(rindex)
  595.         rindex = rindex + incr    'locate next "row" in array by rindex
  596.         rowsFetched = rowsFetched + 1       'track rows fetched
  597.     Next row
  598.     'Tell the RowBuffer how many rows were fetched
  599.     RowBuf.RowCount = rowsFetched
  600.     Exit Sub
  601. End Sub
  602. Private Sub DBGrid1_UnboundWriteData(ByVal RowBuf As RowBuffer, WriteLocation As Variant)
  603.     'if there is no data avaialable, there cannot be an update.
  604.     If MaxRow = 0 Then
  605.         RowBuffer.RowCount = 0  'indicate update failure
  606.         Exit Sub
  607.     End If
  608.     'get the array index of the desired column
  609.     Dim rindex As Integer       'dataval array index for the row
  610.     rindex = GetArrayIndex(WriteLocation, False)
  611.     If Not isInvalidIndex(rindex) Then
  612.         'get the maximum column to process
  613.         Dim collimit As Integer     'limit of RowBuffer columns
  614.         collimit = RowBuf.ColumnCount - 1
  615.         'check each column for an updated value.  For Add and
  616.         'Write operations, the RowBuffer object is a "sparse"
  617.         'storage object, containing Null values for row/column
  618.         'combinations which have not been modified and therefore
  619.         'should not be used as data.
  620.         Dim col As Integer          'column indicator for RowBuffer
  621.         For col = 0 To collimit
  622.             If Not IsNull(RowBuf.Value(0, col)) Then
  623.                 dataval(col, rindex) = RowBuf.Value(0, col)
  624.                 colsUpdated = colsUpdated + 1
  625.             End If
  626.         Next col
  627.     End If
  628. End Sub
  629. 'Other Grid events
  630. Private Sub DBGrid1_KeyPress(KeyAscii As Integer)
  631.     'This KeyPress event traps the return key, and if an
  632.     'AddNew is in progress, then converts the Return into
  633.     'an Update of the Current AddNew, and starts another
  634.     'AddNew.
  635. '** this is not functioning properly yet 
  636. '** the grid does not move to the AddNew row as intended 
  637. '** someday, when there is time ...  <g> 
  638.     If KeyAscii = 13 Then
  639.         'if current is AddNew
  640.         If isAddNew() Then      'isAddNew given above
  641.             KeyAscii = 0
  642.             cmdAddNew_Click 'trigger another AddNew
  643.         End If
  644.     End If
  645. End Sub
  646.